﻿Imports System.Data
Imports Mysoft.Map.Data
Partial Public Class SaleModiTpzk
    Inherits Mysoft.Map.Application.Security.AppPage

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Dim MyBizParamMNG As New Mysoft.PubProject.Business.BizParamMNG
    Dim MySaleMNG As New Mysoft.Slxt.Business.SaleMNG
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码

        Dim strMode, strSaleGUID As String
        strMode = Request.QueryString("mode")
        strSaleGUID = Request.QueryString("SaleGUID")

        '当天时间
        Dim strToday As String
        strToday = Format(Today(), "yyyy-MM-dd")
        txtToday.Value = strToday

        Dim strFuncName As String = Request.QueryString("funcname")
        '如果是变更日志模块过来，标题显示特批折扣日志
        If Not String.IsNullOrEmpty(strFuncName) Then
            If String.Compare(strFuncName, "salemodilog", True) = 0 Then
                titleName.InnerText = "特批折扣变更日志"
            End If
        End If

        '当前操作员
        Dim strUserName As String
        strUserName = Session("UserName")
        txtUserName.Value = strUserName

        ''新增模式

        '取出当前销售单取出对应的客户名称、客户GUID、房间、房间GUID、项目GUID、单位GUID、销售单类型,交易GUID
        Dim dtTrade As DataTable
        Dim strSQL As String
        Dim strCstName, strCstAllGUID, strRoominfo, strRoomGUID, strProjGUID, strBUGUID, strSaletype, strTradeGUID, strProjName, strExecBy, strExecDate, strYwBlDate As String
        Dim strBldArea, strTnArea, strPrice, strTnPrice, strTotal, strCalMode, strPayformName, strDiscntValue, strDiscntRemark, strBldCjPrice, strTnCjPrice, strRoomTotal, strDjBldCjPrice, strDjTnCjPrice, strDjRoomTotal As String
        Dim strZxBz, strZxPrice, strZxTotal, strIsZxkbrht, strFsTotal, strRmbCjTotal, strBz, strExRate, strCjTotal, strStatus, strQSDate, strRgDate, strQyDate, strYwy As String
        Dim s_MjZero, s_PriceZero, s_TotalZero As Integer

        strSQL = "SELECT top 1 CstName,ProjName,CstAllGUID,Roominfo,RoomGUID,vs_Trade1.ProjGUID,vs_Trade1.BUGUID,(case when Saletype='合同' then '合同' else '定单' end)  as SaleType,TradeGUID " & _
         ",BldArea,TnArea,CalMode,Price,TnPrice,Total,Status,QSDate,DiscntValue,BldCjPrice,TnCjPrice,RoomTotal,ZxTotal,FsTotal,DjBldCjPrice,DjTnCjPrice,DjRoomTotal,ywbldate,rgDate,qyDate " & _
          "	,[ZxBz],[ZxPrice] ,[ZxTotal],[IsZxkbrht],[FsTotal],[RmbCjTotal],[Bz],[ExRate],[CjTotal],PayformName,calmode,Ywy  " & _
                 " FROM vs_Trade1 INNER JOIN p_Project ON vs_Trade1.ProjGUID = p_Project.ProjGUID  " & _
                 " WHERE SaleGUID='" & strSaleGUID & "'"
        dtTrade = MyDB.GetDataTable(strSQL)

        If dtTrade.Rows.Count() > 0 Then
            
            strTradeGUID = dtTrade.Rows(0).Item("TradeGUID").ToString()
            strCstName = dtTrade.Rows(0).Item("CstName").ToString()
            strProjName = dtTrade.Rows(0).Item("ProjName").ToString()
            strCstAllGUID = dtTrade.Rows(0).Item("CstAllGUID").ToString()
            strRoominfo = dtTrade.Rows(0).Item("Roominfo").ToString()
            strRoomGUID = dtTrade.Rows(0).Item("RoomGUID").ToString()
            strProjGUID = dtTrade.Rows(0).Item("ProjGUID").ToString()

            '2.获取计算类参数
            '单价、总价保留位(0：元，1：角，2：分)
            s_PriceZero = MySaleMNG.GetSysZero("s_PriceZero", strProjGUID)               '单价保留位
            s_TotalZero = MySaleMNG.GetSysZero("s_TotalZero", strProjGUID)               '总价保留位
            s_MjZero = MySaleMNG.GetSysZero("s_MjZero", strProjGUID)                    '面积保留位

            strBUGUID = dtTrade.Rows(0).Item("BUGUID").ToString()
            strSaletype = dtTrade.Rows(0).Item("Saletype").ToString()

            strBldArea = dtTrade.Rows(0).Item("BldArea").ToString()
            strTnArea = dtTrade.Rows(0).Item("TnArea").ToString()
            strPrice = dtTrade.Rows(0).Item("Price").ToString()
            strTnPrice = dtTrade.Rows(0).Item("TnPrice").ToString()
            strTotal = dtTrade.Rows(0).Item("Total").ToString()
            strCalMode = dtTrade.Rows(0).Item("CalMode").ToString()
            strStatus = dtTrade.Rows(0).Item("Status").ToString()
            strQSDate = dtTrade.Rows(0).Item("QSDate").ToString()

            strDjBldCjPrice = dtTrade.Rows(0).Item("DjBldCjPrice").ToString()
            strDjTnCjPrice = dtTrade.Rows(0).Item("DjTnCjPrice").ToString()
            strDjRoomTotal = dtTrade.Rows(0).Item("DjRoomTotal").ToString()

            strDiscntValue = dtTrade.Rows(0).Item("DiscntValue").ToString()
            strCalMode = dtTrade.Rows(0).Item("calmode").ToString()
            strPayformName = dtTrade.Rows(0).Item("PayformName").ToString()
            strBldCjPrice = dtTrade.Rows(0).Item("BldCjPrice").ToString()
            strTnCjPrice = dtTrade.Rows(0).Item("TnCjPrice").ToString()
            strRoomTotal = dtTrade.Rows(0).Item("RoomTotal").ToString()
            strZxBz = dtTrade.Rows(0).Item("ZxBz").ToString()

            strZxPrice = dtTrade.Rows(0).Item("ZxPrice").ToString()
            strZxTotal = dtTrade.Rows(0).Item("ZxTotal").ToString()
            strIsZxkbrht = dtTrade.Rows(0).Item("IsZxkbrht").ToString()
            strFsTotal = dtTrade.Rows(0).Item("FsTotal").ToString()
            strYwBlDate = dtTrade.Rows(0).Item("ywbldate").ToString()
            strRgDate = dtTrade.Rows(0).Item("rgDate").ToString()
            strQyDate = dtTrade.Rows(0).Item("qyDate").ToString()
            strRmbCjTotal = dtTrade.Rows(0).Item("RmbCjTotal").ToString()
            strBz = dtTrade.Rows(0).Item("Bz").ToString()
            strExRate = dtTrade.Rows(0).Item("ExRate").ToString()
            strCjTotal = dtTrade.Rows(0).Item("CjTotal").ToString()
            strYwy = dtTrade.Rows(0).Item("Ywy").ToString()
        Else
            strBldArea = "0"
            strTnArea = "0"
            strPrice = "0"
            strTnPrice = "0"
            strTotal = "0"
            strCalMode = ""
            strPayformName = ""

            strDiscntValue = "0"
            strDiscntRemark = ""
            strBldCjPrice = "0"
            strTnCjPrice = "0"
            strRoomTotal = "0"
            strZxBz = ""
            strZxPrice = "0"

            strZxPrice = "0"
            strIsZxkbrht = "0"
            strFsTotal = "0"
            strRmbCjTotal = "0"
            strBz = ""
            strExRate = "0"
            strCjTotal = "0"
        End If


        '取出当前交易对应的已交款金额
        Dim strPay As String
        If strTradeGUID <> "" Then
            strSQL = "SELECT sum(BeforeRmbYe) as Pay FROM s_getin WHERE SaleGUID='" & strTradeGUID & "' and (status<>'作废' or status is null)"
            strPay = MyDB.GetDataItemDecimal(strSQL).ToString()
        Else
            strPay = "0"
        End If


        Dim strApplyTypeOption As String = "特批折扣"

        If strMode = "1" Then
            '初始化页面
            appForm.DefaultValueXml = "<xml>" & _
                                        "<BUGUID defaultvalue='" & strBUGUID & "'/>" & _
                                        "<ProjGUID defaultvalue='" & strProjGUID & "'/>" & _
                                        "<ProjGUID1 defaultvalue='" & strProjGUID & "' defaulttext='" & strProjName & "'/>" & _
                                        "<appForm_SaleGUID defaultvalue='" & strSaleGUID & "' defaulttext='详情'/>" & _
                                        "<appForm_TradeGUID defaultvalue='" & strTradeGUID & "'/>" & _
                                        "<SaleGUID defaultvalue='" & strSaleGUID & "'/>" & _
                                        "<SaleType defaultvalue='" & strSaletype & "'/>" & _
                                        "<RoomGUID defaultvalue='" & strRoomGUID & "'/>" & _
                                        "<CstName defaultvalue='" & strCstName & "'/>" & _
                                        "<appForm_ZxTotal defaultvalue='" & strZxTotal & "'/>" & _
                                        "<appForm_BldArea defaultvalue='" & strBldArea & "'/>" & _
                                        "<appForm_TnArea defaultvalue='" & strTnArea & "'/>" & _
                                        "<appForm_Price defaultvalue='" & strPrice & "'/>" & _
                                        "<appForm_TnPrice defaultvalue='" & strTnPrice & "'/>" & _
                                        "<appForm_Total defaultvalue='" & strTotal & "'/>" & _
                                        "<appForm_Status defaultvalue='" & strStatus & "'/>" & _
                                        "<appForm_QSDate defaultvalue='" & strQSDate & "'/>" & _
                                        "<appForm_qyDate defaultvalue='" & strQyDate & "'/>" & _
                                        "<appForm_rgDate defaultvalue='" & strRgDate & "'/>" & _
                                        "<appForm_Ywy defaultvalue='" & strYwy & "'/>" & _
                                        "<appForm_RoomTotal defaultvalue='" & strRoomTotal & "'/>" & _
                                        "<appForm_CalMode defaultvalue='" & strCalMode & "'/>" & _
                                        "<appForm_PayformName defaultvalue='" & strPayformName & "'/>" & _
                                        "<appForm_DiscntValue defaultvalue='" & strDiscntValue & "'/>" & _
                                        "<appForm_BldCjPrice defaultvalue='" & strBldCjPrice & "'/>" & _
                                        "<appForm_TnCjPrice defaultvalue='" & strTnCjPrice & "'/>" & _
                                        "<appForm_FsTotal defaultvalue='" & strFsTotal & "'/>" & _
                                        "<appForm_CjTotal defaultvalue='" & strCjTotal & "'/>" & _
                                        "<appForm_ZxBz defaultvalue='" & strZxBz & "'/>" & _
                                        "<appForm_ZxPrice defaultvalue='" & strZxPrice & "'/>" & _
                                        "<appForm_IsZxkbrht defaultvalue='" & strIsZxkbrht & "'/>" & _
                                        "<appForm_Bz defaultvalue='" & strBz & "'/>" & _
                                        "<appForm_ExRate defaultvalue='" & strExRate & "'/>" & _
                                        "<appForm_newBldCjPrice defaultvalue='" & strBldCjPrice & "'/>" & _
                                        "<appForm_newTnCjPrice defaultvalue='" & strTnCjPrice & "'/>" & _
                                        "<appForm_newCjTotal defaultvalue='" & strCjTotal & "'/>" & _
                                        "<appForm_DjBldCjPrice defaultvalue='" & strDjBldCjPrice & "'/>" & _
                                        "<appForm_DjTnCjPrice defaultvalue='" & strDjTnCjPrice & "'/>" & _
                                        "<appForm_DjRoomTotal defaultvalue='" & strDjRoomTotal & "'/>" & _
                                        "<CstGUID defaultvalue='" & strCstAllGUID & "'/>" & _
                                        "<CstGUID1 defaultvalue='" & strCstAllGUID & "' defaulttext='" & strCstName & "'/>" & _
                                        "<RoomGUID1 defaultvalue='" & strRoomGUID & "' defaulttext='" & strRoominfo & "'/>" & _
                                        "<Pay defaultvalue='" & strPay & "'/>" & _
                                        "<ApproveState defaultvalue='待审批'/>" & _
                                        "<ApplyBy defaultvalue='" & strUserName & "'/>" & _
                                        "<ApplyDate defaultvalue='" & strToday & "'/>" & _
                                        "<ExecBy defaultvalue='" & strExecBy & "'/>" & _
                                        "<ExecDate defaultvalue='" & strExecDate & "'/>" & _
                                        "<ApproveDate defaultvalue='" & strToday & "'/>" & _
                                        "<ApproveBy defaultvalue='" & strUserName & "'/>" & _
                                        "<appForm_ywbldate defaultvalue='" & strYwBlDate & "'/>" & _
                                        "<ApplyType defaultvalue='" & strApplyTypeOption & "'/>" & _
                                        "</xml>"
        End If


        Dim strEnableBgjgSh As String = MyBizParamMNG.GetBizParamConfig("s_EnableTpDiscntSP", strProjGUID)   '启用变更价格审批 ( "0"：不启用；"1"：启用)
        strEnableBgjgSh = IIf(strEnableBgjgSh = "", "1", strEnableBgjgSh)
        txtBgShConfig.Text = strEnableBgjgSh
        '判断用户是否有审核权限
        txtApprovePower.Text = IIf(MySoft.Map.Application.Security.User.CheckUserRight(Session("UserGUID"), "01010305", "10"), 1, 0)

        '成交总价计算方式 (1,以标准总价为基准;2,以标准单价为基准)
        Dim strCalStd As String = MyBizParamMNG.GetBizParamConfig("s_CalStd", strProjGUID)
        txtCalStd.Text = IIf(strCalStd = "", "1", strCalStd)

        txtPriceZero.Text = s_PriceZero.ToString()
        txtTotalZero.Text = s_TotalZero.ToString()

        txtIsjydjx.Text = IIf(Mysoft.Slxt.Business.PublicMng.CheckDjManageEnable(), 1, 0)
    End Sub

    Protected Overrides Sub ConfigureForm()
        appForm.Execute()
    End Sub

End Class
